package com.quasar.hpatient.model.requestmodel;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.provider.Settings;
import android.view.View;

import com.quasar.hpatient.Jpush.MyAlertDialog;
import com.quasar.hpatient.Jpush.NewWorkUtils;
import com.quasar.hpatient.MainAppliaction;
import com.quasar.hpatient.base.BaseActivity;
import com.quasar.hpatient.constant.ConstantManger;
import com.quasar.hpatient.model.custommodel.BloodPressureTableItem;
import com.quasar.hpatient.model.custommodel.BloodSugarTableItem;
import com.quasar.hpatient.model.custommodel.DrugsAdjustmentData;
import com.quasar.hpatient.model.custommodel.InspactionBean;
import com.quasar.hpatient.model.custommodel.InspactionitemBean;
import com.quasar.hpatient.model.custommodel.RemindMedicineTableItem;
import com.quasar.hpatient.model.custommodel.TestTable;
import com.quasar.hpatient.model.custommodel.TestTableItem;
import com.quasar.hpatient.model.httpmodel.AnotherDataResult;
import com.quasar.hpatient.model.httpmodel.AnotherResult;
import com.quasar.hpatient.model.httpmodel.DataHeadResult;
import com.quasar.hpatient.model.httpmodel.DataStateResult;
import com.quasar.hpatient.model.litePalmodel.DailyItemInfodb;
import com.quasar.hpatient.model.litePalmodel.InspectionDetailInfodb;
import com.quasar.hpatient.model.litePalmodel.InspectionInfodb;
import com.quasar.hpatient.model.litePalmodel.InspectionItemInfodb;
import com.quasar.hpatient.model.medicalmodel.ArchivesData;
import com.quasar.hpatient.model.medicalmodel.BaseInfoVersionData;
import com.quasar.hpatient.model.medicalmodel.CarouselData;
import com.quasar.hpatient.model.medicalmodel.CaseinformationData;
import com.quasar.hpatient.model.medicalmodel.ClonePrescriptionData;
import com.quasar.hpatient.model.medicalmodel.CommunityData;
import com.quasar.hpatient.model.medicalmodel.ConsultationBean;
import com.quasar.hpatient.model.medicalmodel.DailyRecordData;
import com.quasar.hpatient.model.medicalmodel.DailyRecordDetailsData;
import com.quasar.hpatient.model.medicalmodel.DiagnoseListData;
import com.quasar.hpatient.model.medicalmodel.DiagnosisData;
import com.quasar.hpatient.model.medicalmodel.DiscomfortData;
import com.quasar.hpatient.model.medicalmodel.DoctorEventData;
import com.quasar.hpatient.model.medicalmodel.DoctorListBean;
import com.quasar.hpatient.model.medicalmodel.FriendsData;
import com.quasar.hpatient.model.medicalmodel.CollectionListData;
import com.quasar.hpatient.model.medicalmodel.HealthRecordsBean;
import com.quasar.hpatient.model.medicalmodel.ListDiagnose;
import com.quasar.hpatient.model.medicalmodel.MedicationRecordData;
import com.quasar.hpatient.model.medicalmodel.OnedayMedicationData;
import com.quasar.hpatient.model.medicalmodel.PatientInfoData;
import com.quasar.hpatient.model.medicalmodel.PrescriptionDayData;
import com.quasar.hpatient.model.medicalmodel.PushinfoData;
import com.quasar.hpatient.model.medicalmodel.QueryAllPrescription;
import com.quasar.hpatient.model.medicalmodel.RecordingAnalysisData;
import com.quasar.hpatient.model.medicalmodel.SelectFriendsData;
import com.quasar.hpatient.model.medicalmodel.SevenDayInspectionData;
import com.quasar.hpatient.model.medicalmodel.TestPresentationData;
import com.quasar.hpatient.model.medicalmodel.TestRecordData;
import com.quasar.hpatient.model.operationmodel.AccountInfo;
import com.quasar.hpatient.network.RetrofitConnection;
import com.quasar.hpatient.onInterface.AnotherResultListener;
import com.quasar.hpatient.utils.LogAndToastUtil;
import com.vise.log.ViseLog;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.Subject;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.http.PATCH;

/**
 * author : 许建宏
 * Date: 2017/10/20 0020
 * View:
 */

public class RequestModel {
    PatientInfoData patient = MainAppliaction.getInstance().getPatient();
    String userCode = MainAppliaction.getInstance().getUserCode();
    Map<String, String> map = MainAppliaction.getInstance().MsgList();

    /**
     * 登陆接口
     *
     * @param name                  账号
     * @param pwd                   密码
     * @param anotherResultListener 回调接口
     */
    public void postLogin(final String name, final String pwd, final AnotherResultListener<PatientInfoData> anotherResultListener) {
        ViseLog.d("enter");

        RetrofitConnection.getRoutineApi()
                .LoginService(name, pwd)
                .subscribeOn(Schedulers.io())
                .observeOn(Schedulers.io())
                .flatMap(new Function<DataStateResult, Observable<DataHeadResult<PatientInfoData>>>() {
                    @Override
                    public Observable<DataHeadResult<PatientInfoData>> apply(@NonNull DataStateResult dataStateResult) throws Exception {

                        ViseLog.d("apply" + dataStateResult);
                        //保存userCode
                        MainAppliaction.getInstance().setUserCode(dataStateResult.getUserCode());
                        //根据返回值判断是否成功
                        if (dataStateResult.getUserCode() != null) {
                            return RetrofitConnection.getRoutineApi().UserInformation(dataStateResult.getUserCode(), name);
                        }
                        //如果getUserCode为空则发送Observable.error
                        return Observable.error(new NullPointerException(dataStateResult.getMsgCode()));
                    }
                }).map(new Function<DataHeadResult, PatientInfoData>() {
            @Override
            public PatientInfoData apply(@NonNull DataHeadResult dataHeadResult) throws Exception {

                ViseLog.d("apply" + dataHeadResult);
                return (PatientInfoData) dataHeadResult.getData();
            }
        }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<PatientInfoData>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull PatientInfoData patientInfoData) {
                        anotherResultListener.onSuccess(patientInfoData);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                        if (notNetwork(e.getMessage())) {
                            if (e.getMessage() != null && e.getMessage().length() > 0) {
                                anotherResultListener.onError(map.get(e.getMessage()));
                            } else {
                                anotherResultListener.onError("");
                            }
                        }

                        ViseLog.d("onError" + e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        anotherResultListener.onRefreshUI();
                    }
                });
    }

    /**
     * 注册
     *
     * @param name 账号
     * @param pwd2 密码
     */
    public void PostRegister(final String name, final String pwd2, final AnotherResultListener<DataStateResult> anotherResultListener) {

        RetrofitConnection.getRoutineApi()
                .RegisterInfo(name, pwd2)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {
                        //判断注册是否成功
                        if (!dataStateResult.getMsgCode().equals("0x00000000")) {
                            throw new RuntimeException(map.get(dataStateResult.getMsgCode()));
                        }
                    }
                })
                .subscribe(new Observer<DataStateResult>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull DataStateResult dataStateResult) {
                        anotherResultListener.onSuccess(dataStateResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (notNetwork(e.getMessage())) {
                            if (e.getMessage() != null && e.getMessage().length() > 0) {
                                anotherResultListener.onError(e.getMessage());
                            } else {
                                anotherResultListener.onError("");
                            }
                            ViseLog.d("onError" + e.getMessage());
                        }

                    }

                    @Override
                    public void onComplete() {
                        anotherResultListener.onRefreshUI();
                    }
                });
    }

    /**
     * 忘记密码
     *
     * @param name 账号
     * @param pwd2 密码
     */
    public void PostForgetPwd(final String name, final String pwd2, final AnotherResultListener<DataStateResult> anotherResultListener) {

        RetrofitConnection.getRoutineApi()
                .ForgetPwd(name, pwd2)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {
                        if (!dataStateResult.getMsgCode().equals("0x00000020")) {
                            throw new RuntimeException(map.get(dataStateResult.getMsgCode()));
                        }
                    }
                })
                .subscribe(new Observer<DataStateResult>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull DataStateResult dataStateResult) {
                        anotherResultListener.onSuccess(dataStateResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (notNetwork(e.getMessage())) {
                            if (e.getMessage() != null && e.getMessage().length() > 0) {
                                anotherResultListener.onError(e.getMessage());
                            } else {
                                anotherResultListener.onError("");
                            }
                            ViseLog.d("onError" + e.getMessage());
                        }
                    }


                    @Override
                    public void onComplete() {
                        anotherResultListener.onRefreshUI();
                    }
                });

    }

    /**
     * @param cover    头像
     * @param nick     昵称
     * @param realName 真实姓名
     * @param bloodId  血型
     * @param idCard   身份证号码
     * @param birthday 出生日期
     * @param sex      性别
     * @param optime   手术日期
     * @param hosId    手术医院
     * @param sourceId 器官来源
     * @param commonId 同供体患者
     * @param address  地址
     */
    public void PostEditUser(String cover, String nick,
                             String realName, String bloodId,
                             String idCard, String birthday,
                             String sex, String optime,
                             String hosId, String sourceId,
                             String commonId, String address, String supervisorDoctor, String protopathy, final AnotherResultListener<DataStateResult> anotherResultListener) {

        ViseLog.d("enter");
        RetrofitConnection.getRoutineApi()
                .UserUpdateInfo(
                        userCode,
                        patient.getId() + "",
                        patient.getPhone(),
                        cover,
                        nick,
                        realName,
                        bloodId,
                        idCard,
                        birthday,
                        sex,
                        optime,
                        hosId,
                        sourceId,
                        commonId,
                        address,
                        supervisorDoctor,
                        protopathy
                )
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                        if (!dataStateResult.getMsgCode().equals("0x00000000")) {

                            throw new RuntimeException(map.get(dataStateResult.getMsgCode()));
                        }
                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ViseLog.d("onError" + e.getMessage());
                    if (e.getMessage() != null && e.getMessage().length() > 0) {
                        anotherResultListener.onError(e.getMessage());
                    } else {
                        anotherResultListener.onError("");
                    }
                    ViseLog.d("onError" + e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                ViseLog.d("onComplete");
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 修改密码
     *
     * @param strOldpwd 旧密码
     * @param strConPwd 新密码
     */
    public void modifyPwd(String strOldpwd, final String strConPwd, final AnotherResultListener<DataStateResult> anotherResultListener) {
        ViseLog.d("enter");
        RetrofitConnection.getRoutineApi()
                .UpPassword(userCode, patient.getId() + "", strOldpwd, strConPwd)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                        if (!dataStateResult.getMsgCode().equals("0x00000020")) {
                            throw new RuntimeException(map.get(dataStateResult.getMsgCode()));
                        }
                    }
                })
                .subscribe(new Observer<DataStateResult>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull DataStateResult dataStateResult) {
                        ViseLog.d("onNext" + dataStateResult);
                        anotherResultListener.onSuccess(dataStateResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                        if (notNetwork(e.getMessage())) {
                            if (e.getMessage() != null && e.getMessage().length() > 0) {
                                anotherResultListener.onError(e.getMessage());
                            } else {
                                anotherResultListener.onError("");
                            }
                            ViseLog.d("onError" + e.getMessage());
                        }

                    }

                    @Override
                    public void onComplete() {
                        ViseLog.d("onComplete");
                        anotherResultListener.onRefreshUI();
                    }
                });
    }


    /**
     * 修改手机号码请求
     *
     * @param newPhone 新手机号码
     */
    public void PostUpPhone(final String newPhone, final AnotherResultListener<DataStateResult> anotherResultListener) {
        String oldPwd = MainAppliaction.getInstance().getPWd();
        ViseLog.d("enter");
        RetrofitConnection.getRoutineApi()
                .UpPhone(userCode, patient.getId() + "", oldPwd, newPhone)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                        if (!dataStateResult.getMsgCode().equals("0x00000000")) {
                            throw new RuntimeException(map.get(dataStateResult.getMsgCode()));
                        }
                    }
                })
                .subscribe(new Observer<DataStateResult>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull DataStateResult dataStateResult) {
                        ViseLog.d("onNext" + dataStateResult);
                        anotherResultListener.onSuccess(dataStateResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (notNetwork(e.getMessage())) {
                            ViseLog.d("onError" + e.getMessage());
                            if (e.getMessage() != null && e.getMessage().length() > 0) {
                                anotherResultListener.onError(e.getMessage());
                            } else {
                                anotherResultListener.onError("");
                            }
                        }

                    }

                    @Override
                    public void onComplete() {
                        ViseLog.d("onComplete");
                        anotherResultListener.onRefreshUI();
                    }
                });
    }

    /**
     * 我的医生列表
     *
     * @param page                  分页
     * @param anotherResultListener
     */
    public void MyDoctors(final String page, final AnotherResultListener<AnotherResult<DoctorListBean>> anotherResultListener) {
        RetrofitConnection.getRoutineApi()
                .MyDoctorListServer(userCode, patient.getId() + "", ConstantManger.userType, page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<AnotherResult<DoctorListBean>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull AnotherResult<DoctorListBean> doctorListBeanAnotherResult) {
                        anotherResultListener.onSuccess(doctorListBeanAnotherResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (notNetwork(e.getMessage())) {
                            if (notNetwork(e.getMessage())) {
                                anotherResultListener.onError(e.getMessage());
                            }
                        }

                    }

                    @Override
                    public void onComplete() {
                        ViseLog.d("onComplete");
                        anotherResultListener.onRefreshUI();
                    }
                });
    }


    /**
     * 医生库
     *
     * @param provenceId
     * @param cityId
     * @param hospitalId
     * @param departmentId
     * @param page
     * @param ResultListener
     */
    public void PostDoctorFind(String provenceId, String cityId, String hospitalId, String departmentId, final String page, String rName, final AnotherResultListener<AnotherResult<DoctorListBean>> ResultListener) {

        ViseLog.d("enter");
        RetrofitConnection.getRoutineApi()
                .DoctorAllServer(userCode, patient.getId() + "", provenceId, cityId, hospitalId, departmentId, ConstantManger.PagerSize, page, rName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<AnotherResult<DoctorListBean>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull AnotherResult<DoctorListBean> doctorListBeanAnotherResult) {
                        ViseLog.d("onNext", doctorListBeanAnotherResult.getList());
                        ResultListener.onSuccess(doctorListBeanAnotherResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        ViseLog.d("onNext", e.getMessage());
                        if (notNetwork(e.getMessage())) {
                            ResultListener.onError(e.getMessage());
                        }

                    }

                    @Override
                    public void onComplete() {
                        ViseLog.d("onComplete");
                        ResultListener.onRefreshUI();
                    }
                });
    }

    /**
     * 好友消息
     *
     * @param ResultListener
     */
    public void PostNewsFriend(final AnotherResultListener<AnotherResult<FriendsData>> ResultListener) {
        ViseLog.d("enter");
        RetrofitConnection.getRoutineApi()
                .FriendNotificationServer(userCode, patient.getId() + "", ConstantManger.userType)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<AnotherResult<FriendsData>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull AnotherResult<FriendsData> friendsDataAnotherResult) {
                        ViseLog.d("onNext", friendsDataAnotherResult);
                        ResultListener.onSuccess(friendsDataAnotherResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (notNetwork(e.getMessage())) {
                            ViseLog.d("onError" + e.getMessage());
                            if (notNetwork(e.getMessage())) {
                                ResultListener.onError(e.getMessage());
                            }
                        }

                    }

                    @Override
                    public void onComplete() {
                        ViseLog.d("onComplete");
                        ResultListener.onRefreshUI();
                    }
                });
    }


    /**
     * 搜索好友
     *
     * @param phone          好友手机号码
     * @param ResultListener
     */
    public void PostAddFriend(String phone, final AnotherResultListener<SelectFriendsData> ResultListener) {

        ViseLog.d("enter");
        RetrofitConnection.getRoutineApi()
                .AddSelectFriendsServer(userCode, patient.getId() + "", ConstantManger.userType, phone)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<SelectFriendsData>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull SelectFriendsData selectFriendsData) {
                        ViseLog.d("onNext" + selectFriendsData);
                        ResultListener.onSuccess(selectFriendsData);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (notNetwork(e.getMessage())) {
                            ViseLog.d("onError" + e.getMessage());
                            ResultListener.onError(e.getMessage());
                        }

                    }

                    @Override
                    public void onComplete() {
                        ViseLog.d("onComplete");
                        ResultListener.onRefreshUI();
                    }
                });
    }

    /**
     * 获取我的好友列表
     */
    public void PostFriendsList(String page, final AnotherResultListener<AnotherResult<FriendsData>> ResultListener) {
        ViseLog.d("enter");
        RetrofitConnection.getRoutineApi()
                .FriendsListServer(userCode, patient.getId() + "", ConstantManger.userType, page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<AnotherResult<FriendsData>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull AnotherResult<FriendsData> friendsDataAnotherResult) {
                        ViseLog.d("onNext" + friendsDataAnotherResult);
                        ResultListener.onSuccess(friendsDataAnotherResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (notNetwork(e.getMessage())) {
                            ViseLog.d("onError" + e.getMessage());
                            ResultListener.onError(e.getMessage());
                        }

                    }

                    @Override
                    public void onComplete() {
                        ViseLog.d("onComplete");
                        ResultListener.onRefreshUI();
                    }
                });
    }

    /**
     * 我的收藏
     */
    public void PostCollection(String page, final AnotherResultListener<AnotherResult<CollectionListData>> ResultListener) {

        ViseLog.d("onRefresh");
        RetrofitConnection.getRoutineApi()
                .MyCollection(patient.getId() + "", userCode, page,ConstantManger.userType)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<AnotherResult<CollectionListData>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {
                    }

                    @Override
                    public void onNext(@NonNull AnotherResult<CollectionListData> myCollectionListDataAnotherResult) {
                        ResultListener.onSuccess(myCollectionListDataAnotherResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (notNetwork(e.getMessage())) {
                            ViseLog.d("onError" + e.getMessage());
                            ResultListener.onError(e.getMessage());
                        }

                    }

                    @Override
                    public void onComplete() {
                        ResultListener.onRefreshUI();
                    }
                });
        ViseLog.d("return");
    }

    /**
     * 自选列表
     *
     * @param page           分页
     * @param ResultListener
     */
    public void PostRecommendList(String page, final AnotherResultListener<AnotherResult<ConsultationBean>> ResultListener) {

        ViseLog.d("PostRecommendList");
        RetrofitConnection.getRoutineApi()
                .RecommendListServer(userCode, page).doOnNext(new Consumer<AnotherResult<ConsultationBean>>() {
            @Override
            public void accept(AnotherResult<ConsultationBean> collectionListDataAnotherResult) throws Exception {

            }
        }).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<AnotherResult<ConsultationBean>>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull AnotherResult<ConsultationBean> collectionListDataAnotherResult) {
                        ResultListener.onSuccess(collectionListDataAnotherResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (notNetwork(e.getMessage())) {
                            ResultListener.onError(e.getMessage());
                        }

                    }

                    @Override
                    public void onComplete() {
                        ResultListener.onRefreshUI();
                    }
                });
    }

    /**
     * 添加好友
     */
    public void PostAddFriends(String phone, final AnotherResultListener<DataStateResult> anotherResultListener) {

        ViseLog.d("enter");
        RetrofitConnection.getRoutineApi()
                .BTFriends(userCode, patient.getId() + "", ConstantManger.userType, phone, ConstantManger.addto)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {
                        if (!dataStateResult.getMsgCode().equals("0x00000000")) {
                            throw new RuntimeException(map.get(dataStateResult.getMsgCode()));
                        }
                    }
                })
                .subscribe(new Observer<DataStateResult>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull DataStateResult dataStateResult) {
                        ViseLog.d("onNext" + dataStateResult);
                        anotherResultListener.onSuccess(dataStateResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (notNetwork(e.getMessage())) {
                            if (e.getMessage() != null && e.getMessage().length() > 0) {
                                anotherResultListener.onError(map.get(e.getMessage()));
                            } else {
                                anotherResultListener.onError("");
                            }
                            ViseLog.d("onError" + e.getMessage());
                        }

                    }

                    @Override
                    public void onComplete() {
                        ViseLog.d("onComplete");
                        anotherResultListener.onRefreshUI();
                    }
                });
    }

    /**
     * 同意/拒绝好友申请
     *
     * @param patientId 好友id
     * @param status    操作状态
     */
    public void operationFriend(String patientId, String status, final AnotherResultListener<DataStateResult> anotherResultListener) {

        RetrofitConnection.getRoutineApi()
                .AddFriendConsentServer(userCode, patientId + "", ConstantManger.userType, patient.getId() + "", status)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                        if (!dataStateResult.getMsgCode().equals("0x00000000")) {
                            throw new RuntimeException(map.get(dataStateResult.getMsgCode()));
                        }
                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    if (e.getMessage() != null && e.getMessage().length() > 0) {
                        anotherResultListener.onError(map.get(e.getMessage()));
                    } else {
                        anotherResultListener.onError("");
                    }
                    ViseLog.d("onError" + e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 历史化验单
     */
    public void HistoryLaboratory(final AnotherResultListener<List<TestTable>> anotherResultListener) {

        List<TestTable> testTables = new ArrayList<>();
        testTables.add(new TestTable(true, "肾功", true));
        testTables.add(new TestTable(new TestTableItem("肌酐", 44, "umol/L", 45)));
        testTables.add(new TestTable(new TestTableItem("肌酐", 44, "umol/L", 45)));
        testTables.add(new TestTable(new TestTableItem("肌酐", 44, "umol/L", 45)));

        testTables.add(new TestTable(true, "肾功", true));
        testTables.add(new TestTable(new TestTableItem("肌酐", 44, "umol/L", 45)));
        testTables.add(new TestTable(new TestTableItem("肌酐", 44, "umol/L", 45)));
        testTables.add(new TestTable(new TestTableItem("肌酐", 44, "umol/L", 45)));
        anotherResultListener.onSuccess(testTables);


    }

    /**
     * 获取历史化验报告日期数据
     *
     * @param startTime             开始时间
     * @param endTime               结束时间
     * @param anotherResultListener
     */
    public void HistoryLaboratorys(String startTime, String endTime, final AnotherResultListener<AnotherResult<TestPresentationData>> anotherResultListener) {

        ViseLog.d("enter+获取历史检查记录");
        RetrofitConnection.getRoutineApi().HistoryLaboratoryServer(userCode, patient.getId() + "", startTime, endTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<TestPresentationData>>() {
                    @Override
                    public void accept(AnotherResult<TestPresentationData> testPresentationDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<TestPresentationData>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull AnotherResult<TestPresentationData> testPresentationDataAnotherResult) {
                ViseLog.d("onNext" + testPresentationDataAnotherResult);
                anotherResultListener.onSuccess(testPresentationDataAnotherResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ViseLog.d("onError" + e.getMessage());
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                ViseLog.d("onComplete");
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 获取单日化验报告
     *
     * @param startTime             当前时间
     * @param anotherResultListener
     */
    public void TestRecordDataModel(String startTime, final AnotherResultListener<AnotherResult<TestRecordData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().TestRecordDataServer(userCode, patient.getId() + "", startTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<TestRecordData>>() {
                    @Override
                    public void accept(AnotherResult<TestRecordData> testRecordDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<TestRecordData>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull AnotherResult<TestRecordData> testRecordDataAnotherResult) {
                anotherResultListener.onSuccess(testRecordDataAnotherResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    //服药提醒
    public void MedicationRemind(final AnotherResultListener<List<RemindMedicineTableItem>> anotherResultListener) {

        List<RemindMedicineTableItem> list = new ArrayList<>();
        list.add(new RemindMedicineTableItem(RemindMedicineTableItem.HEAD));
//        list.add(new RemindMedicineTableItem(RemindMedicineTableItem.BODY, "他克莫司", 2, "10mg/粒", "10:30", 0));
//        list.add(new RemindMedicineTableItem(RemindMedicineTableItem.BODY, "阿司匹林", 2, "10mg/粒", "10:30", 1));
        anotherResultListener.onSuccess(list);

    }

    //血压
    public void BloodPressureData(final AnotherResultListener<List<BloodPressureTableItem>> anotherResultListener) {

        List<BloodPressureTableItem> list = new ArrayList<>();
        list.add(new BloodPressureTableItem(BloodPressureTableItem.HEAD));
        list.add(new BloodPressureTableItem(BloodPressureTableItem.BODY, "09:00", "血压高", "50.9", "50", "低血压", "mmHg"));
        list.add(new BloodPressureTableItem(BloodPressureTableItem.BODY, "09:00", "血压高", "100.5", "60", "低血压", "mmHg"));
        list.add(new BloodPressureTableItem(BloodPressureTableItem.BODY, "09:00", "血压高", "70.4", "70", "低血压", "mmHg"));
        list.add(new BloodPressureTableItem(BloodPressureTableItem.BODY, "09:00", "血压高", "68.1", "80", "低血压", "mmHg"));
        anotherResultListener.onSuccess(list);

    }

    //血糖
    public void BloodSugarData(final AnotherResultListener<List<BloodSugarTableItem>> anotherResultListener) {

        List<BloodSugarTableItem> list = new ArrayList<>();
        list.add(new BloodSugarTableItem(BloodSugarTableItem.HEAD));
        list.add(new BloodSugarTableItem(BloodSugarTableItem.BODY, "09:00", "空腹", "10.2", "mmol/L"));
        list.add(new BloodSugarTableItem(BloodSugarTableItem.BODY, "10:00", "空腹", "15.0", "mmol/L"));
        list.add(new BloodSugarTableItem(BloodSugarTableItem.BODY, "12:00", "空腹", "6.2", "mmol/L"));
        list.add(new BloodSugarTableItem(BloodSugarTableItem.BODY, "20:00", "空腹", "6.2", "mmol/L"));
        anotherResultListener.onSuccess(list);
    }

    /**
     * 不适症状添加
     *
     * @param anotherResultListener
     * @param durationId            时长ID
     * @param description           不适情况描述
     * @param list                  不适症状列表
     *                              longTime  时间  年月日时分秒
     */
    public void AddTroubleDetailData(String durationId, String description, String list, String longTime, String durationLength, final AnotherResultListener<DataStateResult> anotherResultListener) {


        Map<String, RequestBody> partMap = new HashMap<>();

        RequestBody Code = RequestBody.create(MediaType.parse("text/plain"), new String(userCode));
        partMap.put("userCode", Code);

        RequestBody id = RequestBody.create(MediaType.parse("text/plain"), new String(patient.getId() + ""));
        partMap.put("userId", id);

        RequestBody duration = RequestBody.create(MediaType.parse("text/plain"), new String(durationId));
        partMap.put("durationId", duration);


        RequestBody lists = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), list);
        partMap.put("list", lists);


        RequestBody desc = RequestBody.create(MediaType.parse("text/plain"), new String(description));
        partMap.put("description", desc);

        RequestBody Long = RequestBody.create(MediaType.parse("text/plain"), new String(longTime));
        partMap.put("longTime", Long);


        RequestBody durationLengths = RequestBody.create(MediaType.parse("text/plain"), new String(durationLength));
        partMap.put("durationLength", durationLengths);


        RetrofitConnection.getRoutineApi().AddTroubleDetailServer(partMap)
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                        if (!dataStateResult.getMsgCode().equals("0x00000000")) {
                            throw new RuntimeException(map.get(dataStateResult.getMsgCode()));
                        }
                    }
                }).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<DataStateResult>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull DataStateResult dataStateResult) {
                        anotherResultListener.onSuccess(dataStateResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                        if (notNetwork(e.getMessage())) {
                            if (e.getMessage() != null && e.getMessage().length() > 0) {
                                anotherResultListener.onError(map.get(e.getMessage()));
                            } else {
                                anotherResultListener.onError("");
                            }
                            ViseLog.d("onError" + e.getMessage());
                        }

                    }

                    @Override
                    public void onComplete() {
                        anotherResultListener.onRefreshUI();
                    }
                });
    }

    /**
     * 添加化验单
     */

    //检查单检查项目信息
    public InspectionItemInfodb inspectionItem(int primaryid) {

        //保存根据id查出来的检查单检查项目信息
        InspectionItemInfodb inspectionItem = null;
        //获取检查单检查项目信息数据源
        List<InspectionItemInfodb> inspectionItemInfoList = MainAppliaction.getInstance().getInspectionItemInfoList();

        int size = inspectionItemInfoList.size();
        for (int i = 0; i < size; i++) {
            if (primaryid == inspectionItemInfoList.get(i).getPrimaryid()) {
                inspectionItem = inspectionItemInfoList.get(i);
                break;
            }
        }
        return inspectionItem;
    }

    //获取化验报告数据
    public void GetTestData(final AnotherResultListener<List<InspactionBean>> anotherResultListener) {
        List<InspactionBean> mData = new ArrayList<>();

        InspactionBean inspactionBean = new InspactionBean();

//         查询数据库化验单
        List<InspectionInfodb> inspectionInfodbs = MainAppliaction.getInstance().getInspectionInfoList();
        for (int i = 0; i < inspectionInfodbs.size(); i++) {
            inspactionBean.setInspactionName(inspectionInfodbs.get(i).getName());  //保存化验单大项名称
            mData.add(new InspactionBean(InspactionBean.TITLE, inspactionBean.getInspactionName()));
            List<InspectionDetailInfodb> inspectionInfodbs1 = MainAppliaction.getInstance().getInspectionDetailInfodb(inspectionInfodbs.get(i).getPrimaryid() + "");

            for (int j = 0; j < inspectionInfodbs1.size(); j++) {

                //InspectionItemInfodb inspectionItemInfodb=inspectionItem(int primaryid)
                InspactionitemBean inspactionitemBean = new InspactionitemBean();
                inspactionitemBean.setItemName(GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getName()); //保存化验小项名称


                inspactionitemBean.setStandardValue(GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getStandard().replaceAll("&lt;", "<")
                        .replaceAll("&gt;", ">"));//保存化验小项参考值
                inspactionitemBean.setDoseName(GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getDimensionId());  //保存化验小项单位
                if (GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getName().equals("他克莫司")) {
                    inspactionitemBean.setAttribute(0);  //默认项
                    inspactionitemBean.setIsHide("10");

                } else if (GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getName().equals("环孢素谷浓度")) {
                    inspactionitemBean.setAttribute(0);  //默认项
                    inspactionitemBean.setIsHide("10");
                } else if (GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getName().equals("环孢素峰浓度")) {
                    inspactionitemBean.setAttribute(0);  //默认项
                    inspactionitemBean.setIsHide("10");
                }else if (GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getName().equals("西罗莫司")) {
                    inspactionitemBean.setAttribute(0);  //默认项
                    inspactionitemBean.setIsHide("10");
                } else if (GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getName().equals("霉酚酸酯")) {
                    inspactionitemBean.setAttribute(0);  //默认项
                    inspactionitemBean.setIsHide("10");
                } else {
                    inspactionitemBean.setAttribute(inspectionInfodbs1.get(j).getDefaultSelect());  //默认项
                }

                if(GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getBoundary()!=null && GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getBoundary().length()>0){
                    inspactionitemBean.setBoundaryVal(GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getBoundary());//保存边界值
                }
//                else{
//                    inspactionitemBean.setBoundaryVal("0-0");//保存边界值
//                }

                inspactionitemBean.setParamValue(j+"");  //附加值
                inspactionitemBean.setItemValue("");
                inspactionitemBean.setOuterLayerItem(inspactionBean.getInspactionName());

                if (GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getCritical() != null && GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getCritical().length() > 0) {
                    inspactionitemBean.setCriticalValue(GetTestitemlist(inspectionInfodbs1.get(j).getItemid() + "").get(0).getCritical()); //危机值
                } else {
                    inspactionitemBean.setCriticalValue(""); //危机值
                }
                //默认折叠
                if(inspactionitemBean.getAttribute()!=1){
                    if(inspactionitemBean.getIsHide()!=null && inspactionitemBean.getIsHide().length()>0){
                        if(inspactionitemBean.getIsHide().equals("10")){
                            inspactionitemBean.setIsHide("");
                        }else{
                            inspactionitemBean.setIsHide("隐藏");
                        }
                    }else{
                        inspactionitemBean.setIsHide("隐藏");
                    }
                }

                inspactionitemBean.setId(""); //ID
                inspactionitemBean.setInspectionName(inspactionBean.getInspactionName());//大项名称

                //如果检测项目为蛋白质则加载另外一个布局
                if (inspactionitemBean.getItemName().equals("尿蛋白")) {
                    mData.add(new InspactionBean(InspactionBean.PPOTEIN, inspactionitemBean));
                }
                else if(inspactionitemBean.getItemName().contains("定性")){
                    mData.add(new InspactionBean(InspactionBean.PPOTEIN, inspactionitemBean));
                }
                else {
                    mData.add(new InspactionBean(InspactionBean.FROM, inspactionitemBean));
                }
            }
            mData.add(new InspactionBean(InspactionBean.EDIT, true));
        }
        anotherResultListener.onSuccess(mData);

        anotherResultListener.onRefreshUI();

    }

    public List<InspectionItemInfodb> GetTestitemlist(String primaryid) {
        return MainAppliaction.getInstance().getinspectionItemInfodbs(primaryid);
    }


    /**
     * 化验单提交
     *
     * @param list      化验单内容
     * @param checkTime 提交时间
     * @param cover     提交的图片
     */
    public void SubmitTestRecord(String list, String checkTime, String cover, int statusVal, String doctorId, final AnotherResultListener<DataStateResult> anotherResultListener) {


        Map<String, RequestBody> partMap = new HashMap<>();

        RequestBody fileBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), list);
        partMap.put("list", fileBody);

        RequestBody Code = RequestBody.create(MediaType.parse("text/plain"), new String(userCode));
        partMap.put("userCode", Code);

        RequestBody Id = RequestBody.create(MediaType.parse("text/plain"), new String(patient.getId() + ""));
        partMap.put("userId", Id);

        RequestBody Time = RequestBody.create(MediaType.parse("text/plain"), new String(checkTime));
        partMap.put("checkTime", Time);


        RequestBody covers = RequestBody.create(MediaType.parse("text/plain"), new String(cover));
        partMap.put("cover", covers);

        RequestBody status = RequestBody.create(MediaType.parse("text/plain"), new String(statusVal + ""));
        partMap.put("status", status);

        RequestBody doctorIds = RequestBody.create(MediaType.parse("text/plain"), new String(doctorId));
        partMap.put("doctorId", doctorIds);


        RetrofitConnection.getRoutineApi().AddInspectionContentServer(partMap)
                .subscribeOn(Schedulers.io()).
                observeOn(AndroidSchedulers.mainThread()).
                doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {
                        //判断是否成功
                        if (!dataStateResult.getMsgCode().equals("0x00000000")) {
                            throw new RuntimeException(map.get(dataStateResult.getMsgCode()));
                        }
                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    if (e.getMessage() != null && e.getMessage().length() > 0) {
                        anotherResultListener.onError(map.get(e.getMessage()));
                    } else {
                        anotherResultListener.onError("");
                    }
                    ViseLog.d("onError" + e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 患者档案袋信息
     *
     * @param anotherResultListener
     */
    public void ArchivesData(String page, final AnotherResultListener<AnotherResult<ArchivesData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().
                ArchivesDataServer(userCode, patient.getId() + "", ConstantManger.userType,page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<ArchivesData>>() {
                    @Override
                    public void accept(AnotherResult<ArchivesData> archivesDataAnotherResult) throws Exception {
                    }
                }).subscribe(new Observer<AnotherResult<ArchivesData>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull AnotherResult<ArchivesData> archivesDataAnotherResult) {

                anotherResultListener.onSuccess(archivesDataAnotherResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }


    /**
     * 获取诊断消息
     *
     * @param recordTime            开始时间
     * @param endTime               结束时间
     * @param anotherResultListener
     */
    public void DiagnosisData(String recordTime, String endTime, final AnotherResultListener<AnotherResult<DiagnosisData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().DiagnosisDataServer(userCode, patient.getId() + "", recordTime, endTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DiagnosisData>>() {
                    @Override
                    public void accept(AnotherResult<DiagnosisData> diagnosisDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DiagnosisData>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull AnotherResult<DiagnosisData> diagnosisDataAnotherResult) {
                anotherResultListener.onSuccess(diagnosisDataAnotherResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 获取单日不适症状信息
     *
     * @param endTime
     * @param recordTime
     * @param anotherResultListener
     */
    public void DiscomfortData(String endTime, String recordTime, final AnotherResultListener<AnotherResult<DiscomfortData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().DiscomfortDataServer(userCode, patient.getId() + "", endTime, recordTime, "")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DiscomfortData>>() {
                    @Override
                    public void accept(AnotherResult<DiscomfortData> discomfortDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DiscomfortData>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull AnotherResult<DiscomfortData> discomfortDataAnotherResult) {
                anotherResultListener.onSuccess(discomfortDataAnotherResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * @param checkItemId 查看化验项item
     * @param startTime   开始时间
     * @param endTime     结束时间
     */
    public void RecordingAnalysisData(String checkItemId, String startTime, String endTime) {

        RetrofitConnection.getRoutineApi().RecordingAnalysisData(userCode, patient.getId() + "", checkItemId, startTime, endTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<List<RecordingAnalysisData>>>() {
                    @Override
                    public void accept(AnotherResult<List<RecordingAnalysisData>> listAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<List<RecordingAnalysisData>>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull AnotherResult<List<RecordingAnalysisData>> listAnotherResult) {

            }

            @Override
            public void onError(@NonNull Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    /**
     * 申请医生
     *
     * @param doctorId 医生的ID
     */
    public void UpdateDoctorPatientData(String doctorId, final AnotherResultListener<DataStateResult> anotherResultListener) {

        RetrofitConnection.getRoutineApi().UpdateDoctorPatientServer(userCode, patient.getId() + "", doctorId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError("申请医生失败");
                    ViseLog.d("onError" + e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    //获取下一次化验数据数据
    public void NextDayInspectionData(String startTime, final AnotherResultListener<AnotherResult<TestRecordData>> anotherResultListener) {

        ViseLog.d("上一次化验记录");

        RetrofitConnection.getRoutineApi().NextDayInspectionServer(userCode, patient.getId() + "", startTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<TestRecordData>>() {
                    @Override
                    public void accept(AnotherResult<TestRecordData> testRecordDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<TestRecordData>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull AnotherResult<TestRecordData> testRecordDataAnotherResult) {
                anotherResultListener.onSuccess(testRecordDataAnotherResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    //获取上一次数据
    public void LastDayInspectionData(String startTime, final AnotherResultListener<AnotherResult<TestRecordData>> anotherResultListener) {

        ViseLog.d("下一次化验记录");
        RetrofitConnection.getRoutineApi().LastDayInspection(userCode, patient.getId() + "", startTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<TestRecordData>>() {
                    @Override
                    public void accept(AnotherResult<TestRecordData> testRecordDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<TestRecordData>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull AnotherResult<TestRecordData> testRecordDataAnotherResult) {
                anotherResultListener.onSuccess(testRecordDataAnotherResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 修改旋转后的图片
     *
     * @param id
     * @param cover
     * @param anotherResultListener
     */
    public void UpdateInspectionPicData(String id, String cover, final AnotherResultListener<DataStateResult> anotherResultListener) {

        RetrofitConnection.getRoutineApi().UpdateInspectionPicServer(id, cover)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull DataStateResult dataStateResult) {

                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });


    }

    /**
     * 获取折线图
     *
     * @param endTime  结束时间
     * @param itemName 检测item
     */
    public void SevenDayInspectionData(String endTime, String itemName,String type, final AnotherResultListener<SevenDayInspectionData> anotherResultListener) {

        RetrofitConnection.getRoutineApi()
                .SevenDayInspectionServer(userCode, patient.getId() + "", endTime, itemName,type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<SevenDayInspectionData>() {
                    @Override
                    public void accept(SevenDayInspectionData sevenDayInspectionData) throws Exception {

                    }
                }).subscribe(new Observer<SevenDayInspectionData>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull SevenDayInspectionData sevenDayInspectionData) {

                anotherResultListener.onSuccess(sevenDayInspectionData);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 删除检查单项
     *
     * @param id                    检查单item ID
     * @param anotherResultListener
     */
    public void GetRecentDiagnoseData(String id, final AnotherResultListener<DataStateResult> anotherResultListener) {

        RetrofitConnection.getRoutineApi().GetRecentDiagnoseServer(userCode, patient.getId() + "", id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 日历界面展示诊断信息
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     */
    public void DiagnoseListData(String startTime, String endTime, final AnotherResultListener<AnotherResult<DiagnoseListData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().DiagnoseListServer(userCode, patient.getId() + "", startTime, endTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DiagnoseListData>>() {
                    @Override
                    public void accept(AnotherResult<DiagnoseListData> diagnoseListDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DiagnoseListData>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull AnotherResult<DiagnoseListData> diagnoseListDataAnotherResult) {
                anotherResultListener.onSuccess(diagnoseListDataAnotherResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 上次不适症状信息
     *
     * @param recordTime            查询时间
     * @param anotherResultListener
     */
    public void GetRecentTroubleData(String recordTime, final AnotherResultListener<AnotherResult<DiscomfortData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().GetRecentTroubleDetailServer(userCode, patient.getId() + "", recordTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DiscomfortData>>() {
                    @Override
                    public void accept(AnotherResult<DiscomfortData> discomfortDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DiscomfortData>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull AnotherResult<DiscomfortData> discomfortDataAnotherResult) {
                anotherResultListener.onSuccess(discomfortDataAnotherResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 新增药单
     *
     * @param medicineId            药品名称id
     * @param startTime             开始时间
     * @param howtoUse              如何服药id
     * @param howLong               服药天数id
     * @param list                  药品内容
     * @param editMessage           药品变化后生成的字符串
     * @param doctorId              提交的医生id
     * @param id                    克隆id
     * @param periodEnd             结束时间
     * @param mName                 药品名称
     * @param doseName              剂量名称
     * @param packages              单品包装
     * @param useInterval           时间间隔
     * @param anotherResultListener
     */
    public void AddPrescriptionData(
            String medicineId,
            String startTime,
            String howtoUse,
            String howLong,
            String list,
            String editMessage,
            String doctorId,
            String id,
            String periodEnd,
            String mName,
            String doseName,
            String packages,
            String useInterval,
            String timeLen,
            String prescription,
            final AnotherResultListener<DataStateResult> anotherResultListener) {

        Map<String, RequestBody> partMap = new HashMap<>();

        RequestBody Code = RequestBody.create(MediaType.parse("text/plain"), new String(userCode));
        partMap.put("userCode", Code);

        RequestBody patientId = RequestBody.create(MediaType.parse("text/plain"), new String(patient.getId() + ""));
        partMap.put("patientId", patientId);

        RequestBody medicineIds = RequestBody.create(MediaType.parse("text/plain"), new String(medicineId));
        partMap.put("medicineId", medicineIds);

        RequestBody startTimes = RequestBody.create(MediaType.parse("text/plain"), new String(startTime));
        partMap.put("startTime", startTimes);

        RequestBody howtoUses = RequestBody.create(MediaType.parse("text/plain"), new String(howtoUse));
        partMap.put("howtoUse", howtoUses);

        RequestBody howLongs = RequestBody.create(MediaType.parse("text/plain"), new String(howLong));
        partMap.put("howLong", howLongs);

        RequestBody fileBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), list);
        partMap.put("list", fileBody);

        RequestBody editMessages = RequestBody.create(MediaType.parse("text/plain"), new String(editMessage));
        partMap.put("editMessage", editMessages);

        RequestBody doctorIds = RequestBody.create(MediaType.parse("text/plain"), new String(doctorId));
        partMap.put("doctorId", doctorIds);

        RequestBody ids = RequestBody.create(MediaType.parse("text/plain"), new String(id));
        partMap.put("id", ids);

        RequestBody periodEnds = RequestBody.create(MediaType.parse("text/plain"), new String(periodEnd));
        partMap.put("periodEnd", periodEnds);

        RequestBody mNames = RequestBody.create(MediaType.parse("text/plain"), new String(mName));
        partMap.put("mName", mNames);

        RequestBody doseNames = RequestBody.create(MediaType.parse("text/plain"), new String(doseName));
        partMap.put("doseName", doseNames);

        RequestBody packagess = RequestBody.create(MediaType.parse("text/plain"), new String(packages));
        partMap.put("packages", packagess);

        RequestBody useIntervals = RequestBody.create(MediaType.parse("text/plain"), new String(useInterval));
        partMap.put("useInterval", useIntervals);

        RequestBody timeLens = RequestBody.create(MediaType.parse("text/plain"), new String(timeLen));
        partMap.put("timeLen", timeLens);

        RequestBody editTypes = RequestBody.create(MediaType.parse("text/plain"), new String(ConstantManger.userType));
        partMap.put("editType", editTypes);

        //患者名称
        String patientNameVal="";
        if(patient.getRealName()!=null && patient.getRealName().length()>0){
            patientNameVal=patient.getRealName();
        }
        RequestBody patientNames = RequestBody.create(MediaType.parse("text/plain"), new String(patientNameVal));
        partMap.put("patientName", patientNames);

        //医生名称
        RequestBody doctorNames  = RequestBody.create(MediaType.parse("text/plain"), new String(""));
        partMap.put("doctorName", doctorNames);

        //医院名称
        RequestBody hospitalNames  = RequestBody.create(MediaType.parse("text/plain"), new String(""));
        partMap.put("hospitalName", hospitalNames);

        //详情
        RequestBody prescriptions  = RequestBody.create(MediaType.parse("text/plain"), new String(prescription));
        partMap.put("prescription", prescriptions);



        RetrofitConnection.getRoutineApi().AddPrescriptionServer(partMap)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 克隆药单
     *
     * @param doctorId  医生id
     * @param startTime 开始时间
     */
    public void ClonePrescriptionData(String doctorId, String startTime,String mName,String doseName, final AnotherResultListener<ClonePrescriptionData> anotherResultListener) {

        RetrofitConnection.getRoutineApi()
                .ClonePrescriptionServer(userCode, patient.getId() + "", doctorId, startTime,mName,doseName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<ClonePrescriptionData>() {
                    @Override
                    public void accept(ClonePrescriptionData clonePrescriptionData) throws Exception {

                    }
                }).subscribe(new Observer<ClonePrescriptionData>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull ClonePrescriptionData clonePrescriptionData) {
                anotherResultListener.onSuccess(clonePrescriptionData);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 删除验单
     *
     * @param doctorId    医生iD
     * @param id          药单id
     * @param editMessage msg
     */
    public void DeletePrescriptionData(String doctorId, String id, String editMessage,String prescription, final AnotherResultListener<DataStateResult> anotherResultListener) {

        String patientNameVal="";
        if(patient.getRealName()!=null && patient.getRealName().length()>0){
            patientNameVal=patient.getRealName();
        }

        RetrofitConnection.getRoutineApi().DeletePrescriptionServer(userCode, patient.getId() + "", doctorId, id, editMessage, ConstantManger.userType,
                patientNameVal,"","",prescription)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 修改药单
     *
     * @param doctorId    医生id
     * @param pdid
     * @param mid
     * @param editType
     * @param startTime
     * @param howtoUse
     * @param howLong
     * @param list
     * @param editMessage
     * @param id
     * @param periodEnd
     */

    public void updatePrescriptionData(
            String doctorId,
            String pdid,
            String mid,
            String editType,
            String startTime,
            String howtoUse,
            String howLong,
            String list,
            String editMessage,
            String id,
            String periodEnd,
            String mName,
            String doseName,
            String packages,
            String useInterval,
            String timeLen,
            String prescription,

            final AnotherResultListener<DataStateResult> anotherResultListener) {


        Map<String, RequestBody> partMap = new HashMap<>();

        RequestBody Code = RequestBody.create(MediaType.parse("text/plain"), new String(userCode));
        partMap.put("userCode", Code);

        RequestBody patientId = RequestBody.create(MediaType.parse("text/plain"), new String(patient.getId() + ""));
        partMap.put("patientId", patientId);

        RequestBody doctorIds = RequestBody.create(MediaType.parse("text/plain"), new String(doctorId));
        partMap.put("doctorId", doctorIds);

        RequestBody pdids = RequestBody.create(MediaType.parse("text/plain"), new String(pdid));
        partMap.put("pdid", pdids);


        RequestBody mids = RequestBody.create(MediaType.parse("text/plain"), new String(mid));
        partMap.put("mid", mids);

        RequestBody editTypes = RequestBody.create(MediaType.parse("text/plain"), new String(editType));
        partMap.put("editType", editTypes);

        RequestBody startTimes = RequestBody.create(MediaType.parse("text/plain"), new String(startTime));
        partMap.put("startTime", startTimes);

        RequestBody howtoUses = RequestBody.create(MediaType.parse("text/plain"), new String(howtoUse));
        partMap.put("howtoUse", howtoUses);

        RequestBody howLongs = RequestBody.create(MediaType.parse("text/plain"), new String(howLong));
        partMap.put("howLong", howLongs);

        RequestBody fileBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), list);
        partMap.put("list", fileBody);

        RequestBody editMessages = RequestBody.create(MediaType.parse("text/plain"), new String(editMessage));
        partMap.put("editMessage", editMessages);

        RequestBody ids = RequestBody.create(MediaType.parse("text/plain"), new String(id));
        partMap.put("id", ids);

        RequestBody periodEnds = RequestBody.create(MediaType.parse("text/plain"), new String(periodEnd));
        partMap.put("periodEnd", periodEnds);

        RequestBody mNames = RequestBody.create(MediaType.parse("text/plain"), new String(mName));
        partMap.put("mName", mNames);

        RequestBody doseNames = RequestBody.create(MediaType.parse("text/plain"), new String(doseName));
        partMap.put("doseName", doseNames);

        RequestBody packagess = RequestBody.create(MediaType.parse("text/plain"), new String(packages));
        partMap.put("packages", packagess);

        RequestBody useIntervals = RequestBody.create(MediaType.parse("text/plain"), new String(useInterval));
        partMap.put("useInterval", useIntervals);

        RequestBody timeLens = RequestBody.create(MediaType.parse("text/plain"), new String(timeLen));
        partMap.put("timeLen", timeLens);



        //患者名称
        String patientNameVal="";
        if(patient.getRealName()!=null && patient.getRealName().length()>0){
            patientNameVal=patient.getRealName();
        }
        RequestBody patientNames = RequestBody.create(MediaType.parse("text/plain"), new String(patientNameVal));
        partMap.put("patientName", patientNames);

        //医生名称
        RequestBody doctorNames  = RequestBody.create(MediaType.parse("text/plain"), new String(""));
        partMap.put("doctorName", doctorNames);

        //医院名称
        RequestBody hospitalNames  = RequestBody.create(MediaType.parse("text/plain"), new String(""));
        partMap.put("hospitalName", hospitalNames);

        //详情
        RequestBody prescriptions  = RequestBody.create(MediaType.parse("text/plain"), new String(prescription));
        partMap.put("prescription", prescriptions);




        RetrofitConnection
                .getRoutineApi()
                .updatePrescription(partMap)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 一键提交服药信息
     *
     * @param detailId
     * @param anotherResultListener
     */
    public void AddMutiTakeMedicineData(String detailId, final AnotherResultListener<DataStateResult> anotherResultListener) {

        RetrofitConnection.getRoutineApi().AddMutiTakeMedicineServer(userCode, patient.getId() + "", detailId, ConstantManger.MEDICINEBORMAL + "")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 获取单日药单信息
     *
     * @param recordTime            时间
     * @param anotherResultListener
     */
    public void GetPatientSingleDoseDetailData(String recordTime, final AnotherResultListener<AnotherResult<OnedayMedicationData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().GetPatientSingleDoseDetailServer(userCode, patient.getId() + "", recordTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<OnedayMedicationData>>() {
                    @Override
                    public void accept(AnotherResult<OnedayMedicationData> onedayMedicationDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<OnedayMedicationData>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull AnotherResult<OnedayMedicationData> onedayMedicationDataAnotherResult) {
                anotherResultListener.onSuccess(onedayMedicationDataAnotherResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /***
     *一种服药信息提交
     * @param status 提交服药状态
     * @param Id 药单id
     *           detailId
     *           hasServedTime 当前服药时间
     */
    public void AddOneTakeMedicineData(String status, String Id, String detailId, String hasServedTime, final AnotherResultListener<DataStateResult> anotherResultListener) {

        RetrofitConnection.getRoutineApi().AddOneTakeMedicine(userCode, status, Id, detailId, hasServedTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }


    /**
     * 当前药单
     *
     * @param anotherResultListener
     */
    public void GetPatientSinglePrescrptionDetail2Data(final AnotherResultListener<PrescriptionDayData> anotherResultListener) {

        RetrofitConnection.getRoutineApi().GetPatientSinglePrescrptionDetail2Server(userCode, patient.getId() + "")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<PrescriptionDayData>() {
                    @Override
                    public void accept(PrescriptionDayData prescriptionDayData) throws Exception {

                    }
                }).subscribe(new Observer<PrescriptionDayData>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull PrescriptionDayData prescriptionDayData) {
                anotherResultListener.onSuccess(prescriptionDayData);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 获取历史药单
     *
     * @param recordTime
     * @param endTime
     * @param anotherResultListener
     */

    public void GetPatientSinglePrescrptionDetail(String recordTime, String endTime, String page, final AnotherResultListener<PrescriptionDayData> anotherResultListener) {
        RetrofitConnection
                .getRoutineApi()
                .GetPatientSinglePrescrptionDetail(userCode, patient.getId() + "", recordTime, endTime, page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<PrescriptionDayData>() {
                    @Override
                    public void accept(PrescriptionDayData patientSinglePrescrptionAnotherResult) throws Exception {
                        if (!patientSinglePrescrptionAnotherResult.getMsgCode().equals("0x00000000")) {
                            throw new RuntimeException(map.get(patientSinglePrescrptionAnotherResult.getMsgCode()));
                        }
                    }
                })
                .subscribe(new Observer<PrescriptionDayData>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull PrescriptionDayData patientSinglePrescrptionAnotherResult) {
                        anotherResultListener.onSuccess(patientSinglePrescrptionAnotherResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (notNetwork(e.getMessage())) {
                            anotherResultListener.onError(e.getMessage());
                        }
                    }

                    @Override
                    public void onComplete() {
                        anotherResultListener.onRefreshUI();
                    }
                });
    }

    /**
     * 获取服药记录日期
     *
     * @param startTime             开始时间
     * @param endTime               结束时间
     * @param anotherResultListener
     */
    public void MedicationRecordData(String startTime, String endTime, final AnotherResultListener<AnotherResult<MedicationRecordData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi()
                .MedicationRecordDataServer(userCode, patient.getId() + "", startTime, endTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<MedicationRecordData>>() {
                    @Override
                    public void accept(AnotherResult<MedicationRecordData> medicationRecordDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<MedicationRecordData>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull AnotherResult<MedicationRecordData> medicationRecordDataAnotherResult) {
                anotherResultListener.onSuccess(medicationRecordDataAnotherResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });

    }

    /**
     * 获取一天中某项的日常记录
     *
     * @param itemId  日常检查名称
     * @param dayTime 时间
     */
    public void GetUserOneDayDailyRecordData(String itemId, String dayTime,String type, final AnotherResultListener<AnotherResult<DailyRecordDetailsData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().GetUserOneDayDailyRecordServer(userCode, patient.getId() + "", itemId, dayTime,type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DailyRecordDetailsData>>() {
                    @Override
                    public void accept(AnotherResult<DailyRecordDetailsData> dailyRecordDetailsDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DailyRecordDetailsData>>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull AnotherResult<DailyRecordDetailsData> dailyRecordDetailsDataAnotherResult) {
                anotherResultListener.onSuccess(dailyRecordDetailsDataAnotherResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    //下载图片
    public void DownImage(String imageUrls, final AnotherResultListener<Bitmap> anotherResultListener) {
        RetrofitConnection.getPhotoDown()
                .downloadPicFromNet(imageUrls)
                .subscribeOn(Schedulers.newThread())
                .map(new Function<ResponseBody, Bitmap>() {
                    @Override
                    public Bitmap apply(@NonNull ResponseBody responseBody) throws Exception {
                        return BitmapFactory.decodeStream(responseBody.byteStream());
                    }
                }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subject<Bitmap>() {


                               @Override
                               public void onSubscribe(@NonNull Disposable d) {

                               }

                               @Override
                               public void onNext(@NonNull Bitmap bitmap) {
                                   anotherResultListener.onSuccess(bitmap);

                               }

                               @Override
                               public void onError(@NonNull Throwable e) {
                                   if (notNetwork(e.getMessage())) {
                                       ViseLog.d(e.getMessage());
                                       anotherResultListener.onError(e.getMessage());
                                   }

                               }

                               @Override
                               public void onComplete() {
                                   anotherResultListener.onRefreshUI();
                               }

                               @Override
                               protected void subscribeActual(Observer<? super Bitmap> observer) {

                               }

                               @Override
                               public boolean hasObservers() {
                                   return false;
                               }

                               @Override
                               public boolean hasThrowable() {
                                   return false;
                               }

                               @Override
                               public boolean hasComplete() {
                                   return false;
                               }

                               @Override
                               public Throwable getThrowable() {
                                   return null;
                               }
                           }
                );
    }

    /**
     * 删除图片
     *
     * @param id 图片id
     */
    public void DeleteInspectionPicData(String id, final AnotherResultListener<DataStateResult> anotherResultListener) {

        RetrofitConnection.getRoutineApi().DeleteInspectionPicServer(userCode, patient.getId() + "", id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 提交某项日常记录检查信息
     *
     * @param logValue      检测值
     * @param logTime       检测时间
     * @param markValue     标记（如早餐/晚餐）
     * @param paired        第二个检测值
     * @param dailyitemName 检测名称
     * @param dailyitemDose 检测单位
     */
    public void AddDailyRecordDetailData(String logValue, String logTime, String markValue, String paired, String dailyitemName, String dailyitemDose,String warn, final AnotherResultListener<DataStateResult> anotherResultListener) {

        RetrofitConnection.getRoutineApi().AddDailyRecordDetailServer(userCode, patient.getId() + "", logValue, logTime
                , markValue, paired, dailyitemName, dailyitemDose,warn)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(@NonNull Disposable d) {

            }

            @Override
            public void onNext(@NonNull DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    //获取日常记录更多
    public void dailyMoreServer(final AnotherResultListener<List<DailyItemInfodb>> anotherResultListener) {

        List<DailyItemInfodb> dailyItemInfodbList =
                DataSupport.order("primaryid asc").find(DailyItemInfodb.class);

        if (dailyItemInfodbList.size() != 0) {
            anotherResultListener.onSuccess(dailyItemInfodbList);
        } else {
            anotherResultListener.onError("请检查数据库");
        }
    }

    /**
     * 更多日常数据提交
     *
     * @param list                  josn数据
     * @param startTime             开始时间
     * @param anotherResultListener
     */
    public void moreAddDailyRecordData(String list, String startTime, String warn, final AnotherResultListener<DataStateResult> anotherResultListener) {

        Map<String, RequestBody> partMap = new HashMap<>();

        RequestBody Code = RequestBody.create(MediaType.parse("text/plain"), new String(userCode));
        partMap.put("userCode", Code);

        RequestBody userId = RequestBody.create(MediaType.parse("text/plain"), new String(patient.getId() + ""));
        partMap.put("userId", userId);

        RequestBody lists = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), list);
        partMap.put("list", lists);

        RequestBody startTimes = RequestBody.create(MediaType.parse("text/plain"), new String(startTime));
        partMap.put("startTime", startTimes);


        RequestBody warns = RequestBody.create(MediaType.parse("text/plain"), new String(warn));
        partMap.put("warn", warns);

        RetrofitConnection.getRoutineApi().moreAddDailyRecordServer(partMap)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {

                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 提交日常检查项item
     *
     * @param dailyitemName         item名称
     * @param dailyitemDose         item单位
     * @param checkTime             时间
     * @param anotherResultListener
     */
    public void AddDailyItem(String dailyitemName, String dailyitemDose, String checkTime, String itemId, final AnotherResultListener<DataStateResult> anotherResultListener) {

        RetrofitConnection.getRoutineApi().AddDailyItem(userCode, patient.getId() + "", dailyitemName, dailyitemDose, checkTime, itemId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 删除item
     *
     * @param id
     * @param anotherResultListener
     */
    public void DeleteDailyItemData(String id, final AnotherResultListener<DataStateResult> anotherResultListener) {

        RetrofitConnection.getRoutineApi().DeleteDailyItemServer(userCode, id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 查询日常检查项
     *
     * @param startTime             开始时间
     * @param anotherResultListener
     */
    public void GetPatientDailySingleRecordsData(String startTime, final AnotherResultListener<AnotherResult<DailyRecordDetailsData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().GetPatientDailySingleRecords(userCode, patient.getId() + "", startTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DailyRecordDetailsData>>() {
                    @Override
                    public void accept(AnotherResult<DailyRecordDetailsData> dailyRecordDetailsDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DailyRecordDetailsData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<DailyRecordDetailsData> dailyRecordDetailsDataAnotherResult) {
                anotherResultListener.onSuccess(dailyRecordDetailsDataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 获取历史日常检查日期数据
     *
     * @param startTime
     * @param endTime
     * @param anotherResultListener
     */
    public void GetPatientDailyRecordsData(String startTime, String endTime, final AnotherResultListener<AnotherResult<DailyRecordData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().GetPatientDailyRecordsServer(userCode, patient.getId() + "", startTime, endTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DailyRecordData>>() {
                    @Override
                    public void accept(AnotherResult<DailyRecordData> dailyRecordDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DailyRecordData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<DailyRecordData> dailyRecordDataAnotherResult) {
                anotherResultListener.onSuccess(dailyRecordDataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 历史日常记录折线图
     *
     * @param itemName  item名称
     * @param startTime 开始时间
     * @param endTime   结束时间
     */
    public void GetUserAloneItemDailyRecordData(String itemName, String startTime, String endTime, final AnotherResultListener<AnotherResult<DailyRecordDetailsData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().GetUserAloneItemDailyRecordServer(userCode, patient.getId() + "", itemName, startTime, endTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DailyRecordDetailsData>>() {
                    @Override
                    public void accept(AnotherResult<DailyRecordDetailsData> dataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DailyRecordDetailsData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<DailyRecordDetailsData> dataAnotherResult) {
                anotherResultListener.onSuccess(dataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 查询历史日常一天的折线图
     *
     * @param itemName              item名称
     * @param startTime             开始时间
     * @param endTime               结束时间
     * @param anotherResultListener
     */
    public void GetUserDailyRecord_AWeek2Server(String itemName, String startTime, String endTime, final AnotherResultListener<AnotherResult<DailyRecordDetailsData>> anotherResultListener) {
        RetrofitConnection.getRoutineApi().GetUserDailyRecord_AWeek2(userCode, patient.getId() + "", itemName, startTime, endTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DailyRecordDetailsData>>() {
                    @Override
                    public void accept(AnotherResult<DailyRecordDetailsData> dataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DailyRecordDetailsData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<DailyRecordDetailsData> dataAnotherResult) {
                anotherResultListener.onSuccess(dataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 根据医生的环信id查询医生的信息
     *
     * @param bomName               环信id
     * @param anotherResultListener
     */
    public void User_ChangeBomNameData(String bomName, final AnotherResultListener<AnotherDataResult<DoctorListBean>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().User_ChangeBomNameServer(userCode, patient.getId() + "", bomName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherDataResult<DoctorListBean>>() {
                    @Override
                    public void accept(AnotherDataResult<DoctorListBean> doctorListBeanAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherDataResult<DoctorListBean>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherDataResult<DoctorListBean> doctorListBeanAnotherResult) {
                anotherResultListener.onSuccess(doctorListBeanAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }


    /**
     * 单项提交患者信息
     *
     * @param rowName               列名
     * @param content               修改的值
     * @param anotherResultListener tableName 表名称
     */
    public void SubmitAloneUserInformationData(String rowName, String content, String tableName, final AnotherResultListener<DataStateResult> anotherResultListener) {

        RetrofitConnection.getRoutineApi().SubmitAloneUserInformationServer(userCode, patient.getId() + "", rowName, content, tableName)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                anotherResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    public void QueryAllPrescription(String page, final AnotherResultListener<AnotherResult<DrugsAdjustmentData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().QueryAllPrescription(userCode, patient.getId() + "", page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DrugsAdjustmentData>>() {
                    @Override
                    public void accept(AnotherResult<DrugsAdjustmentData> drugsAdjustmentDataAnotherResult) throws Exception {

                    }
                })
                .subscribe(new Observer<AnotherResult<DrugsAdjustmentData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<DrugsAdjustmentData> prescriptionDayData) {
                anotherResultListener.onSuccess(prescriptionDayData);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                    ViseLog.d("获取调药记录信息" + e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });

    }


    /**
     * 获取个人资料
     *
     * @param anotherResultListener
     */

    public void UserInformationData(final AnotherResultListener<DataHeadResult<PatientInfoData>> anotherResultListener) {
        RetrofitConnection.getRoutineApi().UserInformation(userCode, patient.getId() + "").subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataHeadResult<PatientInfoData>>() {
                    @Override
                    public void accept(DataHeadResult<PatientInfoData> patientInfoDataDataHeadResult) throws Exception {

                    }
                }).subscribe(new Observer<DataHeadResult<PatientInfoData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataHeadResult<PatientInfoData> patientInfoDataDataHeadResult) {
                AccountInfo.saveAccount(MainAppliaction.getInstance(), patientInfoDataDataHeadResult.getData());
                anotherResultListener.onSuccess(patientInfoDataDataHeadResult);
            }

            @Override
            public void onError(Throwable e) {
                anotherResultListener.onError(e.getMessage());
            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }


    //转存图片
    public void LXT_AddInspection(String patientid, String inspectionTypeTime, String Cover, final AnotherResultListener<DataStateResult> onDataHeadResultListener) {

        RetrofitConnection.getRoutineApi()
                .LXT_AddInspection(userCode, patientid, "", inspectionTypeTime, Cover)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                })
                .subscribe(new Observer<DataStateResult>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull DataStateResult dataStateResult) {
                        onDataHeadResultListener.onSuccess(dataStateResult);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (notNetwork(e.getMessage())) {
                            onDataHeadResultListener.onError(e.getMessage());
                        }

                    }

                    @Override
                    public void onComplete() {
                        onDataHeadResultListener.onRefreshUI();
                    }
                });
    }

    /**
     * 同共体患者
     *
     * @param phone
     * @param onDataHeadResultListener
     */
    public void SelectTheTotalBodyData(String phone, final AnotherResultListener<DataStateResult> onDataHeadResultListener) {
        RetrofitConnection.getRoutineApi()
                .SelectTheTotalBody3(userCode, patient.getId() + "", phone)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                onDataHeadResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    onDataHeadResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                onDataHeadResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 同供体患者获取
     *
     * @param onDataHeadResultListener
     */
    public void SelectTheTotalBody2Server(final AnotherResultListener<DataHeadResult<PatientInfoData>> onDataHeadResultListener) {

        RetrofitConnection.getRoutineApi()
                .SelectTheTotalBody2Server(userCode, patient.getId() + "")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataHeadResult<PatientInfoData>>() {
                    @Override
                    public void accept(DataHeadResult<PatientInfoData> dataDataHeadResult) throws Exception {

                    }
                }).subscribe(new Observer<DataHeadResult<PatientInfoData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataHeadResult<PatientInfoData> dataDataHeadResult) {
                onDataHeadResultListener.onSuccess(dataDataHeadResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    onDataHeadResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                onDataHeadResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 帖子评论
     *
     * @param postId                   帖子id
     * @param commentContent           评论
     * @param onDataHeadResultListener
     */
    public void UpdateCommentPostData(String postId, String commentContent, final AnotherResultListener<DataStateResult> onDataHeadResultListener) {

        RetrofitConnection.getRoutineApi()
                .UpdateCommentPostServer(userCode, patient.getId() + "", postId, commentContent, ConstantManger.userType)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                onDataHeadResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    onDataHeadResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                onDataHeadResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 帖子点赞
     *
     * @param postId                   帖子id
     * @param onDataHeadResultListener
     */
    public void UpdatePraisePostData(String postId, final AnotherResultListener<DataStateResult> onDataHeadResultListener) {

        RetrofitConnection.getRoutineApi()
                .UpdatePraisePostServer(userCode, patient.getId() + "", postId, ConstantManger.EditType)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                onDataHeadResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                onDataHeadResultListener.onError(e.getMessage());
            }

            @Override
            public void onComplete() {
                onDataHeadResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 获取发帖列表
     *
     * @param page                     分页
     * @param onDataHeadResultListener
     */
    public void GetPostListData(String page, final AnotherResultListener<AnotherResult<CommunityData>> onDataHeadResultListener) {

        RetrofitConnection.getRoutineApi()
                .GetPostListServer(userCode, "", page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<CommunityData>>() {
                    @Override
                    public void accept(AnotherResult<CommunityData> communityDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<CommunityData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<CommunityData> communityDataAnotherResult) {
                onDataHeadResultListener.onSuccess(communityDataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    onDataHeadResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                onDataHeadResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 生命史
     *
     * @param startTime
     * @param endTime
     * @param page                     type 条件查询
     * @param onDataHeadResultListener
     */
    public void LXT_HealthRecordsData(String startTime, String endTime, String page, String type, final AnotherResultListener<HealthRecordsBean> onDataHeadResultListener) {
        RetrofitConnection.getRoutineApi()
                .LXT_HealthRecordsServer(userCode, patient.getId() + "", startTime, endTime, page, type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<HealthRecordsBean>() {
                    @Override
                    public void accept(HealthRecordsBean healthRecordsBean) throws Exception {

                    }
                }).subscribe(new Observer<HealthRecordsBean>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(HealthRecordsBean healthRecordsBean) {
                onDataHeadResultListener.onSuccess(healthRecordsBean);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    onDataHeadResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                onDataHeadResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 获取一天诊断信息
     *
     * @param dayTime 时间
     */
    public void LXT_GetRecentDiagnoseListData(String dayTime, final AnotherResultListener<AnotherResult<DiagnosisData>> onDataHeadResultListener) {

        RetrofitConnection.getRoutineApi().LXT_GetRecentDiagnoseListServer(userCode, patient.getId() + "", dayTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DiagnosisData>>() {
                    @Override
                    public void accept(AnotherResult<DiagnosisData> diagnosisDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DiagnosisData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<DiagnosisData> diagnosisDataAnotherResult) {
                onDataHeadResultListener.onSuccess(diagnosisDataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    onDataHeadResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                onDataHeadResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 查询推送的消息
     */
    public void GetUserLatestMessageData(String page, final AnotherResultListener<AnotherResult<PushinfoData>> onDataHeadResultListener) {

        RetrofitConnection.getRoutineApi().GetUserLatestMessage(userCode, patient.getId() + "", ConstantManger.userType, page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<PushinfoData>>() {
                    @Override
                    public void accept(AnotherResult<PushinfoData> pushinfoDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<PushinfoData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<PushinfoData> pushinfoDataAnotherResult) {
                onDataHeadResultListener.onSuccess(pushinfoDataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    onDataHeadResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                onDataHeadResultListener.onRefreshUI();
            }
        });

    }

    /**
     * 用户发帖
     *
     * @param content                  发帖内容
     * @param cover                    发帖图片
     * @param onDataHeadResultListener
     */
    public void PublicPostInfoData(String content, String cover, final AnotherResultListener<DataStateResult> onDataHeadResultListener) {

        RetrofitConnection.getRoutineApi().PublicPostInfoServer(userCode, patient.getId() + "", content, ConstantManger.userType, cover)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                onDataHeadResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    onDataHeadResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                onDataHeadResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 热门医生列表
     *
     * @param page
     * @param ResultListener
     */
    public void StarDoctorList(String page, final AnotherResultListener<AnotherResult<DoctorListBean>> ResultListener) {

        RetrofitConnection.getRoutineApi().StarDoctorList(userCode, patient.getId() + "", page)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DoctorListBean>>() {
                    @Override
                    public void accept(AnotherResult<DoctorListBean> doctorListBeanAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DoctorListBean>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<DoctorListBean> doctorListBeanAnotherResult) {
                ResultListener.onSuccess(doctorListBeanAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 咨询轮播
     *
     * @param page           分页
     * @param ResultListener
     */
    public void GetCarouselInformationsData(String page, final AnotherResultListener<AnotherResult<CarouselData>> ResultListener) {

        RetrofitConnection.getRoutineApi().GetCarouselInformationsServer(userCode, patient.getId() + "", page, ConstantManger.PAGESIZECONSULTATION)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<CarouselData>>() {
                    @Override
                    public void accept(AnotherResult<CarouselData> carouselDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<CarouselData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<CarouselData> carouselDataAnotherResult) {
                ResultListener.onSuccess(carouselDataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 判断该咨询是否已经收藏
     *
     * @param recordId
     */
    public void GetCollectionInfoExistData(String recordId, final AnotherResultListener<DataStateResult> ResultListener) {

        RetrofitConnection.getRoutineApi().GetCollectionInfoExistServer(userCode, patient.getId() + "", recordId,ConstantManger.userType)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                ResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 收藏咨询
     *
     * @param recordId
     * @param ResultListener
     */
    public void UpdateMedicalInformationCollectData(String recordId, final AnotherResultListener<DataStateResult> ResultListener) {

        RetrofitConnection.getRoutineApi().UpdateMedicalInformationCollect(userCode, patient.getId() + "", recordId,ConstantManger.userType)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                ResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 添加病例
     *
     * @param hosId       医院id
     * @param title       标题
     * @param description 描述
     * @param createTime  创建时间
     * @param cover       病例图片
     */
    public void AddPatientCaseHistoryData(String hosId, String title, String description, String createTime, String cover, final AnotherResultListener<DataStateResult> ResultListener) {

        RetrofitConnection.getRoutineApi().AddPatientCaseHistoryServer(userCode, patient.getId() + "", hosId, title, description, createTime, cover)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                ResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 获取病例信息
     *
     * @param startTime      开始时间
     * @param endTime        结束时间
     * @param ResultListener
     */
    public void GetPatientCaseHistoryData(String startTime, String endTime, final AnotherResultListener<AnotherResult<CaseinformationData>> ResultListener) {

        RetrofitConnection.getRoutineApi().GetPatientCaseHistoryServer(userCode, patient.getId() + "", startTime, endTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<CaseinformationData>>() {
                    @Override
                    public void accept(AnotherResult<CaseinformationData> caseinformationDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<CaseinformationData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<CaseinformationData> caseinformationDataAnotherResult) {
                ResultListener.onSuccess(caseinformationDataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 删除患者病例
     * @param id
     * @param ResultListener
     */
    public void DeletePatientCaseServer(String id,final AnotherResultListener<DataStateResult> ResultListener){

        RetrofitConnection.getRoutineApi().DeletePatientCaseServer(userCode,patient.getId()+"",id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                ResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 修改病例信息
     */
    public void UpdatePatientCase(String id,String title,String description,String cover,String createTime,String hosId,final AnotherResultListener<DataStateResult> ResultListener){

        RetrofitConnection.getRoutineApi().UpdatePatientCaseServer(userCode,patient.getId()+"",id,title,description,cover,createTime,hosId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                ResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 查看消息
     */
    public void UpdateUserMessageData(String id, final AnotherResultListener<DataStateResult> ResultListener) {

        RetrofitConnection.getRoutineApi().UpdateUserMessageServer(userCode, id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                ResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 根据医生的id查询医生的信息
     */
    public void GetMyPatientInfoListData(String doctorId, final AnotherResultListener<AnotherDataResult<DoctorListBean>> ResultListener) {

        RetrofitConnection.getRoutineApi().GetMyPatientInfoListServer(userCode, doctorId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherDataResult<DoctorListBean>>() {
                    @Override
                    public void accept(AnotherDataResult<DoctorListBean> doctorListBeanAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherDataResult<DoctorListBean>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherDataResult<DoctorListBean> doctorListBeanAnotherResult) {
                ResultListener.onSuccess(doctorListBeanAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 修改日常记录
     *
     * @param id        修改的itemID
     * @param logValue  检测值
     * @param paired    第二个检测值
     * @param markValue 标签id
     *                  type=0删除，1修改
     */
    public void updateAloneItemDailyRecordDetailData(String id, String logValue, String paired, String markValue, String type,String warn,String indexId,
                                                     final AnotherResultListener<DataStateResult> ResultListener) {

        RetrofitConnection.getRoutineApi().updateAloneItemDailyRecordDetailServer(userCode, id, logValue, paired, markValue, type,warn,indexId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                ResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ResultListener.onError(e.getMessage());
                }
            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 上次日常数据
     *
     * @param toDay
     * @param anotherResultListener
     */
    public void lastDailyRecordListData(String toDay, final AnotherResultListener<AnotherResult<DailyRecordDetailsData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().lastDailyRecordListServer(userCode, patient.getId() + "", toDay)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DailyRecordDetailsData>>() {
                    @Override
                    public void accept(AnotherResult<DailyRecordDetailsData> dataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DailyRecordDetailsData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<DailyRecordDetailsData> dataAnotherResult) {
                anotherResultListener.onSuccess(dataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 查询下次数据
     *
     * @param toDay
     * @param anotherResultListener
     */
    public void GetNextDailyRecordListData(String toDay, final AnotherResultListener<AnotherResult<DailyRecordDetailsData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().GetNextDailyRecordListServer(userCode, patient.getId() + "", toDay)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DailyRecordDetailsData>>() {
                    @Override
                    public void accept(AnotherResult<DailyRecordDetailsData> dataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DailyRecordDetailsData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<DailyRecordDetailsData> dataAnotherResult) {
                anotherResultListener.onSuccess(dataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    //上次服药信息
    public void GetlastPatientDoseIndexData(String toDay, final AnotherResultListener<AnotherResult<OnedayMedicationData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().GetlastPatientDoseIndexServer(userCode, patient.getId() + "", toDay)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<OnedayMedicationData>>() {
                    @Override
                    public void accept(AnotherResult<OnedayMedicationData> onedayMedicationDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<OnedayMedicationData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<OnedayMedicationData> onedayMedicationDataAnotherResult) {
                anotherResultListener.onSuccess(onedayMedicationDataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    //下次服药信息
    public void GetNextPatientDoseIndexData(String toDay, final AnotherResultListener<AnotherResult<OnedayMedicationData>> anotherResultListener) {

        RetrofitConnection.getRoutineApi().GetNextPatientDoseIndexServer(userCode, patient.getId() + "", toDay)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<OnedayMedicationData>>() {
                    @Override
                    public void accept(AnotherResult<OnedayMedicationData> onedayMedicationDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<OnedayMedicationData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<OnedayMedicationData> onedayMedicationDataAnotherResult) {
                anotherResultListener.onSuccess(onedayMedicationDataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    anotherResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                anotherResultListener.onRefreshUI();
            }
        });
    }

    //提醒复诊消息
    public void GetUserLatestMessageExData(final AnotherResultListener<AnotherResult<PushinfoData>> onDataHeadResultListener) {

        RetrofitConnection.getRoutineApi().GetUserLatestMessageEx(userCode, patient.getId() + "", ConstantManger.userType, "14","")
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<PushinfoData>>() {
                    @Override
                    public void accept(AnotherResult<PushinfoData> pushinfoDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<PushinfoData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<PushinfoData> pushinfoDataAnotherResult) {
                onDataHeadResultListener.onSuccess(pushinfoDataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    onDataHeadResultListener.onError(e.getMessage());
                }

            }

            @Override
            public void onComplete() {
                onDataHeadResultListener.onRefreshUI();
            }
        });
    }

    //删除医生
    public void DeletePatientData(String doctorId, final AnotherResultListener<DataStateResult> ResultListener) {

        RetrofitConnection.getRoutineApi().DeletePatient(userCode, patient.getId() + "", doctorId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                ResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                if (notNetwork(e.getMessage())) {
                    ResultListener.onError("取消关注失败");
                }

            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }


    public boolean notNetwork(String msg) {

        boolean isNet = true;

        if (msg != null) {
            if (msg.contains("connect")) {
                this.netType = NewWorkUtils.getNetWorkState(MainAppliaction.getInstance());
                if (!isNetConnect()) {
                    //网络异常，请检查网络
                    LogAndToastUtil.toast(MainAppliaction.getInstance(), "网络异常，请检查网络");
                    isNet = false;
                }
            }else if(msg.contains("time")){
                LogAndToastUtil.toast(MainAppliaction.getInstance(), "网络异常，请检查网络");
                isNet = false;
            }
            return isNet;
        }else{
            return false;
        }
    }


    private int netType;

    /**
     * 判断有无网络 。
     *
     * @return true 有网, false 没有网络.
     */
    public boolean isNetConnect() {
        if (netType == 1) {
            return true;
        } else if (netType == 0) {
            return true;
        } else if (netType == -1) {
            return false;
        }
        return false;
    }

    public void GetPatientInspectionListAndDiagnoseList(String startTime,String endTime, final AnotherResultListener<ListDiagnose> ResultListener){

        RetrofitConnection.getRoutineApi().LXT_GetPatientInspectionListAndDiagnoseList(userCode,patient.getId()+"",startTime,endTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<ListDiagnose>() {
                    @Override
                    public void accept(ListDiagnose listDiagnose) throws Exception {
                        if (!listDiagnose.getMsgCode().equals("0x00000000")) {
                            throw new RuntimeException(map.get(listDiagnose.getMsgCode()));
                        }
                    }
                })
                .subscribe(new Observer<ListDiagnose>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull ListDiagnose listDiagnose) {
                        ResultListener.onSuccess(listDiagnose);
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        if (notNetwork(e.getMessage())) {
                            ResultListener.onError(e.getMessage());
                        }
                    }

                    @Override
                    public void onComplete() {
                        ResultListener.onRefreshUI();
                    }
                });

    }

    /**
     * 查看医生提交的事件
     * @param recordTime
     * @param endTime
     * @param ResultListener
     */
    public void GetPatientSingleInspectionEvent(String recordTime,String endTime,final AnotherResultListener<AnotherResult<DoctorEventData>> ResultListener){

        RetrofitConnection.getRoutineApi().GetPatientSingleInspectionEvent(userCode,patient.getId()+"","",recordTime,endTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DoctorEventData>>() {
                    @Override
                    public void accept(AnotherResult<DoctorEventData> doctorEventDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DoctorEventData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<DoctorEventData> doctorEventDataAnotherResult) {
                ResultListener.onSuccess(doctorEventDataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                ResultListener.onError(e.getMessage());
            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });

    }

    /**
     * 获取医生的诊断信息
     * @param startTime
     * @param ResultListener
     */
    public void QueryGetPatientDiagnoseLsitData(String startTime,final AnotherResultListener<AnotherResult<DiagnosisData>> ResultListener ){

        RetrofitConnection.getRoutineApi().QueryGetPatientDiagnoseLsitServer(userCode,patient.getId()+"",startTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<DiagnosisData>>() {
                    @Override
                    public void accept(AnotherResult<DiagnosisData> diagnosisDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<DiagnosisData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<DiagnosisData> diagnosisDataAnotherResult) {
                ResultListener.onSuccess(diagnosisDataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                ResultListener.onError(e.getMessage());
            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 修改事件信息
     * @param troubleName
     * @param durationLength
     * @param logTime
     * @param description
     * @param ResultListener
     */
    public void AmmTroubleDetailServer(String troubleName,String durationLength,String logTime,String description,String id,final AnotherResultListener<DataStateResult> ResultListener){
        RetrofitConnection.getRoutineApi().AmmTroubleDetail(userCode,patient.getId()+"",troubleName,durationLength,logTime,description,id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                ResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                ResultListener.onError(e.getMessage());
            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 删除事件
     */
    public void DeleteEvent(String id,final AnotherResultListener<DataStateResult> ResultListener){
        RetrofitConnection.getRoutineApi().
                DelTroubleDetail(userCode,patient.getId()+"",id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                ResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                ResultListener.onError(e.getMessage());
            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }


    /**
     * 计步器
     * @param dataValue
     * @param logTime
     * @param ResultListener
     */
    public void AddExternalRecords(String dataValue,String logTime,final AnotherResultListener<DataStateResult> ResultListener){

        RetrofitConnection.getRoutineApi().AddExternalRecords(userCode,patient.getId()+"",ConstantManger.userType,dataValue,logTime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<DataStateResult>() {
                    @Override
                    public void accept(DataStateResult dataStateResult) throws Exception {

                    }
                }).subscribe(new Observer<DataStateResult>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DataStateResult dataStateResult) {
                ResultListener.onSuccess(dataStateResult);
            }

            @Override
            public void onError(Throwable e) {
                ResultListener.onError(e.getMessage());
            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 数据库版本检测
     */
    public void CommonBaseInfoVersion(final AnotherResultListener<AnotherResult<BaseInfoVersionData>> ResultListener){

        RetrofitConnection.getRoutineApi().CommonBaseInfoVersion()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<BaseInfoVersionData>>() {
                    @Override
                    public void accept(AnotherResult<BaseInfoVersionData> baseInfoVersionDataAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<BaseInfoVersionData>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<BaseInfoVersionData> baseInfoVersionDataAnotherResult) {
                ResultListener.onSuccess(baseInfoVersionDataAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                ResultListener.onError(e.getMessage());
            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }

    /**
     * 获取更新表里的数据
     * @param tableName
     * @param version
     * @param ResultListener
     */
    public void GetQueryAllFromInformationServer(String tableName,String version,final AnotherResultListener<AnotherResult<Object>> ResultListener){

        RetrofitConnection.getRoutineApi().GetQueryAllFromInformation(userCode,patient.getId()+"",tableName,version)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<AnotherResult<Object>>() {
                    @Override
                    public void accept(AnotherResult<Object> objectAnotherResult) throws Exception {

                    }
                }).subscribe(new Observer<AnotherResult<Object>>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(AnotherResult<Object> objectAnotherResult) {
                ResultListener.onSuccess(objectAnotherResult);
            }

            @Override
            public void onError(Throwable e) {
                ResultListener.onError(e.getMessage());
            }

            @Override
            public void onComplete() {
                ResultListener.onRefreshUI();
            }
        });
    }


}
